Skip to content

fix: msj_data prepare_prompts ignores dataset_names parameter and uses mutable default - #311

Open
zhanz5 wants to merge 1 commit into
msoedov:mainfrom
zhanz5:fix/msj-prepare-prompts-mutable-default
Open

fix: msj_data prepare_prompts ignores dataset_names parameter and uses mutable default#311
zhanz5 wants to merge 1 commit into
msoedov:mainfrom
zhanz5:fix/msj-prepare-prompts-mutable-default

Conversation

@zhanz5

@zhanz5 zhanz5 commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

The prepare_prompts() function had two bugs:

  1. Mutable default argument: dataset_names=[] is a Python anti-pattern that shares the same list object across calls.
  2. Logic bug: the return statement iterated over dataset_map keys instead of the dataset_names parameter, always returning all datasets regardless of what was requested.

Changes:

  • probe_data/msj_data.py:

    • Changed default from dataset_names=[] to dataset_names=None
    • Added None check to initialize empty list
    • When dataset_names is provided, only return matching datasets
    • When empty or None, return all datasets (backward compatible)
  • probe_data/test_msj_data.py:

    • Fixed test_dataset_contents assertion: passing 1 dataset name should return 1 result, not 2 (old test was verifying the buggy behavior)

…s mutable default

The prepare_prompts() function had two bugs:
1. Mutable default argument: dataset_names=[] is a Python anti-pattern
   that shares the same list object across calls.
2. Logic bug: the return statement iterated over dataset_map keys instead
   of the dataset_names parameter, always returning all datasets regardless
   of what was requested.

Changes:

- probe_data/msj_data.py:
  - Changed default from dataset_names=[] to dataset_names=None
  - Added None check to initialize empty list
  - When dataset_names is provided, only return matching datasets
  - When empty or None, return all datasets (backward compatible)

- probe_data/test_msj_data.py:
  - Fixed test_dataset_contents assertion: passing 1 dataset name should
    return 1 result, not 2 (old test was verifying the buggy behavior)

@JackSpiece JackSpiece left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The return value now respects dataset_names, but both datasets are still loaded before that filter runs because the dictionary values call load_dataset_generic(...) eagerly. Selecting one dataset will still download both, and a failure in the unselected loader can abort the scan. Could we store loader callables in the map and invoke only the selected names? A test that asserts the unselected loader is never called would catch this.

@msoedov

msoedov commented Jul 31, 2026

Copy link
Copy Markdown
Owner

Mutable default argument: dataset_names=[] is a Python anti-pattern that shares the same list object across calls.

This reads like an AI-generated review. dataset_names=[] is fine as long as you always copy it before mutation. Using a nullable parameter as the default is worse.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants